package aygx.spring.boot.principle.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author 暗影孤星
 * @date 2022/7/25 22:54
 * @description
 */
@Slf4j
public class MyImportSelector implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata metadata) {
        // selectImports, aygx.spring.boot.principle.Content3
        // metadata 指的是有@Import()注解的类
//        log.info("selectImports, {}",metadata.getClassName());
//        if (metadata.hasAnnotation("org.springframework.context.annotation.Import")) {
//            return new String[]{"aygx.spring.boot.principle.entity.Dog"};
//        }
//        return new String[]{"aygx.spring.boot.principle.entity.Mouse"};

        try {
            if (Class.forName("aygx.spring.boot.principle.entity.Mouse") != null) {
                return new String[]{"aygx.spring.boot.principle.entity.Dog"};
            }
        } catch (ClassNotFoundException e) {
            return null;
        }
        return null;
    }
}